package com.test.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.entity.Student;
import com.test.entity.Teacher;
import com.test.mapper.TeacherMapper;
import com.test.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    @Cacheable(value = "teacherCache", key = "'teacher_page_' + #page + '_' + #size")
    public void delete(Integer id) {
        teacherMapper.deleteById(id);
    }

    @Override
    @CacheEvict(value = "teacherCache", allEntries = true)
    public Page<Teacher> pages(Integer page, Integer size) {
        Page<Teacher> teachers=new Page<>(page,size);
        teacherMapper.selectPage(teachers,null);
        return teachers;
    }
}
